
.EQU	ADCON_VAL,	0X1004	; ENABLE AD CONVERT AND ACLK / 5 =24M
.EQU	ADPCFG_VAL,	0XFFcc	; AN5, AN4, AN1, AN0 <= ON 0xffc0
.EQU	ADCPC0_VAL,	0X0404	; AN3,2,1,0 AS TRIGGER SOURCE, PWM1 AS OUTPUT
;.EQU	ADCPC0_VAL,	0X0000	; AN1 & AN0 AS TRIGGER SOURCE, PWM1 AS OUTPUT
.EQU	ADCPC1_VAL,	0X0606	; AN5 & AN4 AS TRIGGER SOURCE, PWM1 AS OUTPUT


.INCLUDE	"p33FJ16GS502.INC"
.INCLUDE	"MACRO.INC"
.GLOBAL		AD_INITIAL


.TEXT

AD_INITIAL:
	MOVFF	#ADCON_VAL, ADCON
	MOVFF	#ADPCFG_VAL, ADPCFG
	MOVFF	#ADCPC0_VAL, ADCPC0
	MOVFF	#ADCPC1_VAL, ADCPC1
	
	MOVFF	#0X0200, IPC27	;0x2000 AD PAIR 1(AN2,AN3) 
							;WITH INTERRUPT PRIORITY 002 
							;0x0100 AD PAIR 0(AN1,AN0) 
							;WITH INTERRUPT PRIORITY 001

	BCLR	IFS6, #ADCP0IF	; CLR ADCP0 FLG
	BCLR	IFS6, #ADCP1IF	; CLR ADCP1 FLG
	
	BSET	IEC6, #ADCP0IE	; ENABLE ADCP0 INTERRUPT
	BSET	IEC6, #ADCP1IE	; ENABLE ADCP1 INTERRUPT

	NOP
	NOP
	NOP
	
	MOVFF	#0x0003, IPC28	; 0x0003 ;AD PAIR 2(AN5,AN4) 
							; WITH INTERRUPT PRIORITY 003
	BCLR	IFS7, #ADCP2IF	; CLEAR INTERRUPT FLAG OF AD PAIR 2
	BSET	IEC7, #ADCP2IE	; ENABLE INTERRUPT ON AD PAIR 2
	
	BSET	ADCON, #ADON
	RETURN

	.END
		